package com.xianyl.libsforandroid.flash;

import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * 引导页面适配器
 * @author xianyl
 * @date 2015-3-3 下午9:35:21
 */
public class VPAdapter extends PagerAdapter {

	// 界面列表
	private List<View> views;

	public VPAdapter(List<View> views) {
		this.views = views;
	}

	// 初始化position位置的界面
	@Override
	public Object instantiateItem(View viewPager, int position) {
		((ViewPager) viewPager).addView(views.get(position), 0);

		return views.get(position);
	}

	@Override
	// 销毁position位置的界面
	public void destroyItem(View viewPager, int position, Object object) {
		((ViewPager) viewPager).removeView(views.get(position));
	}

	@Override
	public void finishUpdate(View view) {
	}

	@Override
	// 获得当前界面数
	public int getCount() {
		return views==null ? 0 : views.size();
	}

	@Override
	// 判断是否由对象生成界面
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public void restoreState(Parcelable parcelable, ClassLoader classLoader) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View view) {
	}

}
